package com.hq.fxh.CustomerView;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.PopupWindow;

import com.hq.fxh.No0_ChengQu.Adapter.Adapter_ShareMenu;
import com.hq.fxh.R;
import com.hq.fxh.Utils.Tool;


/**
 * @author wanglubin
 * @ClassName ShareDialogUtils
 * @Description :分享弹窗工具类
 * @Created 2015/11/18
 * @Email 422695989@qq.com
 */
public class ShareDialogUtils {
    public static String[] titles;

    static {
        titles = new String[]{"微信好友", "微信朋友圈", "QQ", "QQ空间", "新浪微博", "复制链接"};
    }

    public static PopupWindow popupWindow;
     /**
     * 显示分享
     *
     * @param context
     * @param v
       */

    public static PopupWindow showShareView(final Context context, final View v, final SharePopCallBack sharePopCallBack) {
        LayoutInflater inflater = (LayoutInflater)
                context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.view_share, null);
        XGridView gvShare = (XGridView) view.findViewById(R.id.gvShare);
        Button btnCancel = (Button) view.findViewById(R.id.btnCancel);


        int[] resIds = new int[]{R.mipmap.iconfont_weixin, R.mipmap.iconfont_wei_xin_cicle, R.mipmap.iconfont_qq, R.mipmap.iconfont_qqkongjian, R.mipmap.iconfont_weibo, R.mipmap.iconfont_lianjie};

        Adapter_ShareMenu adapter = new Adapter_ShareMenu(resIds, titles, (Activity) context);
        gvShare.setAdapter(adapter);
        gvShare.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                dismiss();
                sharePopCallBack.Call(adapterView,view,i,l);
            }
        });
        popupWindow = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setContentView(view);
        popupWindow.setFocusable(true);
        popupWindow.setOutsideTouchable(true);
        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                Tool.setAlpha((Activity) context,1f);
            }
        });
        popupWindow.setAnimationStyle(R.style.popwin_anim_style);

        popupWindow.showAtLocation(v,
                Gravity.BOTTOM | Gravity.CENTER_VERTICAL, 0, 0);
        Tool.setAlpha((Activity) context,0.6f);

        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });
        return popupWindow;
    }

    public static void dismiss() {
        if (popupWindow != null && popupWindow.isShowing()) {
            popupWindow.dismiss();
        }
    }
    public  interface SharePopCallBack{
       void Call(AdapterView<?> adapterView, View view, int position, long l);
    }


}
